package com.example.mapper;

import com.example.entity.Building;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 操作building相关数据接口
*/
public interface BuildingMapper {

    /**
      * 新增
    */
    int insert(Building building);

    /**
      * 删除
    */
    int deleteById(Integer id);

    /**
      * 修改
    */
    int updateById(Building building);

    /**
      * 根据ID查询
    */
    Building selectById(Integer id);

    /**
      * 查询所有
    */
    List<Building> selectAll(Building building);

    @Select("SELECT * FROM building where name =#{name}")
    Building selectByName(String name);

    @Select("SELECT num FROM building where id =#{buildingId}")
    Integer selectByCondition(Integer buildingId);

    @Update("update building set num = num -1 where id =#{buildingId} and num > 0")
    void decreaseNum(Integer buildingId);

    @Update("update building set num = num +1 where id =#{buildingId}")
    void increaseNum(Integer buildingId);
}